import { ARecord, ARecordCreate, ARecordUpdate } from "../types/CdnARecord";
import axiosInstance from "./axios";

const API_URL = '/config/cdn/arecord';
const CNameAPI = {
  // 查询所有
  getAll: (params?: Record<string, any>) => {
    return axiosInstance.get<ARecord[]>(`${API_URL}`, { params });
  },

  //查询部署的cname
  getEnable: (params?: Record<string, any>) => {
    return axiosInstance.get<ARecord[]>(`${API_URL}/online`);
  },

  // 查询单条
  getById: (id: number) => {
    return axiosInstance.get<ARecord>(`${API_URL}/${id}`);
  },

  // 创建
  create: (data: ARecordCreate) => {
    return axiosInstance.post<ARecord>(`${API_URL}`, data);
  },

  // 更新
  update: (id: number, data: ARecordUpdate) => {
    return axiosInstance.put<ARecord>(`${API_URL}/${id}`, data);
  },

  // 删除
  delete: (id: number) => {
    return axiosInstance.delete<ARecord>(`${API_URL}/${id}`);
  },

  // 部署
  deploy: (id: number) => {
    return axiosInstance.post<{ message: string }>(`${API_URL}/deploy/${id}`);
  },

  // 下线
  offline: (id: number) => {
    return axiosInstance.post<{ message: string }>(`${API_URL}/offline/${id}`);
  }


};

export default CNameAPI;